package cn.wostore.wxhelper.Xposed;

import android.content.ContentValues;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;

/**
 * @author wuch
 * @date 2019/1/4 0004
 */
public class DatabaseInsertHook extends XC_MethodHook {
    private LoadHook loadHook;

    public DatabaseInsertHook(LoadHook loadHook) {
        this.loadHook = loadHook;
    }

    @Override
    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
        super.afterHookedMethod(param);
//        StackTraceElement[] stackTrace = new Throwable().getStackTrace();
//        if (stackTrace != null){
//            XposedBridge.log(Arrays.toString(stackTrace));
//        }
//        XposedBridge.log(Arrays.toString(param.args));

        String tableName = (String) param.args[0];
        if (!tableName.equals("message"))
            return;
        XposedBridge.log(param.args[2].toString());
        ContentValues contentValues = (ContentValues) param.args[2];
        SendMessageUtil sendMessageUtil = new SendMessageUtil(this.loadHook.classLoader, this.loadHook.launcherUI, contentValues);
        sendMessageUtil.reply();
    }
}
